﻿using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;

public class SVNTools
{
    private static string GetSVNPath()
    {
        string file = Application.dataPath;
        List<string> files = new List<string>(); 
        foreach (Object obj in Selection.objects)
        {
            string path = AssetDatabase.GetAssetPath(obj);
            if (!string.IsNullOrEmpty(path))
            {
                files.Add(path);
                path = AssetDatabase.GetTextMetaFilePathFromAssetPath(path);
                if (!string.IsNullOrEmpty(path))
                    files.Add(path);
            }
        }
        if (files.Count > 0)
        {
            file = string.Join("*", files.ToArray());
        }
        return file;
    }


    [MenuItem("Assets/TortoiseSVN/Update", false, 1)]
    public static void UpdateSVN()
    {
        System.Diagnostics.Process.Start("TortoiseProc.exe", "/command:update /path:" + Application.dataPath);// GetSVNPath());
    }

    [MenuItem("Assets/TortoiseSVN/Commit", false, 2)]
    public static void CommitSVN()
    {
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        System.Diagnostics.Process.Start("TortoiseProc.exe", "/command:commit /path:" + GetSVNPath());
    }

    [MenuItem("Assets/TortoiseSVN/Add", false, 3)]
    public static void ShowAddSVN()
    {
        System.Diagnostics.Process.Start("TortoiseProc.exe", "/command:add /path:" + GetSVNPath());
    }
    [MenuItem("Assets/TortoiseSVN/Revert", false, 4)]
    public static void RevertSVN()
    {
        System.Diagnostics.Process.Start("TortoiseProc.exe", "/command:revert /path:" + GetSVNPath());
    }

    [MenuItem("Assets/TortoiseSVN/Clean Up", false, 5)]
    public static void CleanUpSVN()
    {
        System.Diagnostics.Process.Start("TortoiseProc.exe", "/command:cleanup /path:" + GetSVNPath());
    }

    [MenuItem("Assets/TortoiseSVN/Show Log", false, 6)]
    public static void ShowLogSVN()
    {
        System.Diagnostics.Process.Start("TortoiseProc.exe", "/command:log /path:" + GetSVNPath());
    }

}
